package com.cw.lang.validator.constraintvalidators;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import com.cw.lang.validator.constraints.MobilePhoneCheck;

/**
 * @author zhengqy@yunrong.cn
 * @version V2.1
 * @since 2.1.0 2019/3/20 10:31
 */
public class MobilePhoneCheckValidator implements ConstraintValidator<MobilePhoneCheck, String> {

    private String rexgep;

    @Override
    public void initialize(MobilePhoneCheck constraintAnnotation) {
        this.rexgep = constraintAnnotation.regexp();
    }

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        //若电话号码为空，不进行校验
        if (null == s) {
            return true;
        }
        if (s.matches(rexgep)) {
            return true;
        }
        return false;
    }
}
